package com.fsk.user.config;

import com.netflix.appinfo.ApplicationInfoManager;
import com.netflix.discovery.DiscoveryClient;
import com.netflix.discovery.EurekaClientConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;


@Configuration
public class EurekaConfig {

    /**
     * eureka DiscoveryClient需要的参数
     */
    @Autowired
    private EurekaClientConfig eurekaClientConfig;

    /**
     * eureka DiscoveryClient需要的参数
     */
//    @Qualifier("eurekaApplicationInfoManager")
    @Qualifier("eurekaApplicationInfoManager")
    @Autowired
    private ApplicationInfoManager applicationInfoManager;

    @Bean
    public DiscoveryClient.DiscoveryClientOptionalArgs discoveryClientOptionalArgs() {
        DiscoveryClient.DiscoveryClientOptionalArgs discoveryClientOptionalArgs = new DiscoveryClient.DiscoveryClientOptionalArgs();
        return discoveryClientOptionalArgs;
    }

    /**
     * 注入eureka client 与 server交互对象
     */
    @Bean
    public DiscoveryClient discoveryClient() {
        DiscoveryClient discoveryClient = new DiscoveryClient(applicationInfoManager, eurekaClientConfig);
        return discoveryClient;
    }
}
